﻿<rules>
  <rule id="SvcDoc.Core.1001" category="core" target="servicedoc" specificationsection ="2.2.6.2.7" requirementlevel="should" format="xml">
    <description>A data service SHOULD represent all available collections in a single &lt;app:workspace&gt; element.</description>
    <action processor="rng">
      <grammar xmlns="http://relaxng.org/ns/structure/1.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:app="http://www.w3.org/2007/app">
        <start>
          <element>
            <!-- service level element can be ignored since the workspace element is the focus here. -->
            <anyName />
            <ref name="anyAttributes" />
            <interleave>
              <element name="app:workspace">
                <ref name="anyAttributes" />
                <interleave>
                  <zeroOrMore>
                    <element name="app:collection">
                      <ref name="anyContent" />
                    </element>
                  </zeroOrMore>
                  <zeroOrMore>
                    <ref name="anyElement_other_than_app_collection" />
                  </zeroOrMore>
                </interleave>
              </element>
              <zeroOrMore>
                <ref name="anyElement_other_than_app_workspace" />
              </zeroOrMore>
            </interleave>
          </element>
        </start>
        <define name="anyAttributes">
          <zeroOrMore>
            <choice>
              <attribute>
                <anyName />
              </attribute>
            </choice>
          </zeroOrMore>
        </define>
        <define name="anyElement">
          <element>
            <anyName />
            <zeroOrMore>
              <choice>
                <attribute>
                  <anyName />
                </attribute>
                <text />
                <ref name="anyElement" />
              </choice>
            </zeroOrMore>
          </element>
        </define>
        <define name="anyContent">
          <zeroOrMore>
            <choice>
              <attribute>
                <anyName />
              </attribute>
              <text />
              <ref name="anyElement" />
            </choice>
          </zeroOrMore>
        </define>
        <define name="anyElement_other_than_app_collection">
          <element>
            <choice>
              <anyName>
                <except>
                  <nsName ns="http://www.w3.org/2007/app" />
                </except>
              </anyName>
              <nsName ns="http://www.w3.org/2007/app">
                <except>
                  <name>app:collection</name>
                </except>
              </nsName>
            </choice>
            <ref name="anyContent" />
          </element>
        </define>
        <define name="anyElement_other_than_app_workspace">
          <element>
            <choice>
              <anyName>
                <except>
                  <nsName ns="http://www.w3.org/2007/app" />
                </except>
              </anyName>
              <nsName ns="http://www.w3.org/2007/app">
                <except>
                  <name>app:workspace</name>
                </except>
              </nsName>
            </choice>
            <ref name="anyAttributes" />
            <zeroOrMore>
              <ref name="anyElement_other_than_app_collection" />
            </zeroOrMore>
          </element>
        </define>
      </grammar>
    </action>
    <errormessage>A data service SHOULD represent all available collections in a single &lt;app:workspace&gt; element.</errormessage>
  </rule>
</rules>
